package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.post.PostSearchProject;
import com.zxkj.commonpatrol.model.response.InspectionDetailResponse;
import com.zxkj.commonpatrol.model.response.ProjectDetailResponse;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ProjectCheckPointListRepoisity extends BaseRepository {
    public ProjectCheckPointListRepoisity() {

    }
    //初始化選擇項目列表
    public void  getSelectProject(int type,MyBaseDataCallBack mDataCallBack){
        List<SelectProjectEntrity> datas=new ArrayList<>();

        if (type==2){
            for (int i = 6; i < 9; i++) {
                datas.add(new SelectProjectEntrity(i+1+"","100"+i,"深圳"+i,"CheckPoint"+i,"ce"+i));
            }
        }else if (type==1){
            for (int i = 3; i < 6; i++) {
                datas.add(new SelectProjectEntrity(i+1+"","100"+i,"深圳"+i,"CheckPoint"+i,"ce"+i));
            }
        }else{
            for (int i = 0; i < 3; i++) {
                datas.add(new SelectProjectEntrity(i+1+"","100"+i,"深圳"+i,"CheckPointf"+i,"ce"+i));
            }
        }

        mDataCallBack.onDataSuccessCallBack(datas);

    }

    //获取巡查点列表

    public  void getCheckList(String RouteInspectNo,String Filter,int Categoryid,int PageSize,int PageIndex,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        PostSearchProject postSearchProject  =new PostSearchProject();
        postSearchProject.setRouteInspectNo(RouteInspectNo);
        postSearchProject.setCategoryid(Categoryid);
        postSearchProject.setFilter(Filter);
        postSearchProject.setPageIndex(PageIndex);
        postSearchProject.setPageSize(PageSize);


        ETFApiHelper.geRadomApi().getCheckPointList(map,new BaseHttpUtil<PostSearchProject>().convertVo2Json(postSearchProject))
                .compose(Transformer.<InspectionDetailResponse>switchSchedulers())
                .subscribe(new CommonObserver<InspectionDetailResponse>() {
                    @Override
                    protected String setTag() {
                        return "RouteSystems";
                    }

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(InspectionDetailResponse s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }


}
